package com.h3c.nem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.custom.BusinessException;
import com.eos.common.util.IdWorker;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.h3c.nem.dto.TbApprovalRecordDTO;
import com.h3c.nem.entity.*;
import com.h3c.nem.enums.FileOpTypeEnum;
import com.h3c.nem.mapper.*;
import com.h3c.nem.service.CommService;
import com.h3c.nem.service.ITbFlowInstService;
import com.h3c.nem.service.ITbNewerTaskService;
import com.h3c.nem.dto.TbNewerTaskDTO;
import com.h3c.nem.utils.BusiEnumDefine;
import com.h3c.nem.utils.InitExampleOrderByUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Copyright (C), 2020-2020, h3c
 * FileName: TbNewerTaskServiceImpl
 *
 * @Author: l22886
 * @Date: 2022-01-24
 * Description: tb_newer_task serviceImpl
 * Version: 1.0
 */
@Slf4j
@Service
public class TbNewerTaskServiceImpl extends ServiceImpl<TbNewerTaskMapper, TbNewerTask> implements ITbNewerTaskService {

    @Resource
    private TbNewerTaskMapper tbNewerTaskMapper;

    @Autowired
    private CommService commService;

    @Autowired
    private TbFlowInstMapper tbflowINstMapper;

    @Autowired
    private ITbFlowInstService iTbFlowInstService;

    @Autowired
    private SdTodoTaskServiceImpl todoTaskService;

    @Autowired
    private SdEmailTemplateMapper sdEmailTemplateMapper;

    @Autowired
    public TbApprovalRecordMapper tbApprovalRecordMapper;

    //小任务审批流程编号
    public static final String N5 = "N5";

    @Autowired
    private TbWorkerMapper tbWorkerMapper;
    @Autowired
    private SdUploadFileMapper sdUploadFileMapper;

    /**
     * @title: selectFuzzyByDto
     * @description: 模糊查询操作
     * @params: [ dto ]
     * @return: java.util.List
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public List<TbNewerTaskDTO> selectFuzzyByDto(TbNewerTaskDTO dto) {
//        if (!commService.checkLoginUserRole(BusiEnumDefine.USER_ROLE_ADMIN)) {
//            throw new BusinessException(StatusCodeEnum.UN_AUTH);
//        }
        QueryWrapper<TbNewerTask> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(dto.getTaskName())) {
            queryWrapper.like("task_name", dto.getTaskName());
        }
        if (dto.getTaskTargetWorker() != null) {
            queryWrapper.eq("task_target_worker", dto.getTaskTargetWorker());
        }
        if (dto.getEnableFlag() != null) {
            queryWrapper.eq("enable_flag", dto.getEnableFlag());
        }
        List<TbNewerTask> tasks = getBaseMapper().selectList(queryWrapper);

        List<TbNewerTaskDTO> taskDTOS = JSONArray.parseArray(JSONArray.toJSONString(tasks), TbNewerTaskDTO.class);
        boolean isAdmin = commService.checkLoginUserRole(BusiEnumDefine.USER_ROLE_ADMIN);
        String loginUserNameAndId = commService.getLoginUserNameAndId();

        for (TbNewerTaskDTO taskDTO : taskDTOS) {
            String targetConfigValue = taskDTO.getTargetConfigValue();
            if (StringUtils.isBlank(targetConfigValue)) {
                taskDTO.setTargetConfigValueStr("全部部门");
            } else {
                StringBuilder nameStr = new StringBuilder();
                for (String deptId : targetConfigValue.split(",")) {
                    SdDept sdDept = commService.getSdDept(deptId);
                    nameStr.append(sdDept.getDeptName()).append(",");
                }
                taskDTO.setTargetConfigValueStr(nameStr.substring(0, nameStr.length()- 1));
            }

            SdAllWorker allWorkerDoFromLocalCache = commService.getAllWorkerDoFromLocalCache(taskDTO.getApproverId());
            if (allWorkerDoFromLocalCache != null) {
                taskDTO.setApproverName(allWorkerDoFromLocalCache.getWorkerName());
            }

            if (isAdmin || loginUserNameAndId.equals(taskDTO.getCreatorInfo())) {
                taskDTO.setCanEdit("1");
            } else {
                taskDTO.setCanEdit("0");
            }
        }
        return taskDTOS;
    }

    /**
     * @title: selectByDto
     * @description: 精确查询操作
     * @params: [ dto ]
     * @return: java.util.List
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public List<TbNewerTaskDTO> selectByDto(TbNewerTaskDTO dto) {
        //List<TbNewerTask> list = tbNewerTaskMapper.selectByExample(initExample(dto));
        List<TbNewerTask> list = tbNewerTaskMapper.queryList(JSONObject.parseObject(JSONObject.toJSONString(dto), TbNewerTask.class));
        return JSONArray.parseArray(JSONArray.toJSONString(list), TbNewerTaskDTO.class);
    }

    /**
     * @title: insertDto
     * @description: 插入操作
     * @params: [ dto ]
     * @return: Integer
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public String insertDto(TbNewerTaskDTO dto) {
        Date date = new Date();
        String userIdAndName = commService.getLoginUserNameAndId();
        if (null == dto.getTaskId() || "".equals(dto.getTaskId())) {
            String pkId = IdWorker.nextId() + "";
            dto.setTaskId(pkId);
            dto.setCreateTime(date);
            dto.setCreatorInfo(userIdAndName);
        }
        String value = dto.getTargetConfigValue();
        if (StringUtils.isBlank(value)) {
            dto.setTargetType(1);
        } else {
            dto.setTargetType(2);
        }
        dto.setUpdateTime(date);
        dto.setUpdatorInfo(userIdAndName);
        saveOrUpdate(JSONObject.parseObject(JSON.toJSONString(dto), TbNewerTask.class));
        return dto.getTaskId();
    }

    /**
     * @title: updateDto
     * @description: 修改操作
     * @params: [ dto ]
     * @return: Integer
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public String updateDto(TbNewerTaskDTO dto) {
        Date date = new Date();
        String userIdAndName = commService.getLoginUserNameAndId();
        if (!commService.checkLoginUserRole(BusiEnumDefine.USER_ROLE_ADMIN)) {
            TbNewerTask newerTask = tbNewerTaskMapper.selectById(dto.getTaskId());
            String creatorInfo = newerTask.getCreatorInfo();
            if (!creatorInfo.equals(userIdAndName)) {
                throw new BusinessException(StatusCodeEnum.UN_AUTH);
            }
        }
        String value = dto.getTargetConfigValue();
        if (StringUtils.isBlank(value)) {
            dto.setTargetType(1);
        } else {
            dto.setTargetType(2);
        }
        dto.setUpdateTime(date);
        dto.setUpdatorInfo(userIdAndName);
        TbNewerTask tbNewerTask = JSONObject.parseObject(JSON.toJSONString(dto), TbNewerTask.class);
        Integer integer = tbNewerTaskMapper.updateTbNewerTask(tbNewerTask);
        //删除文件
        QueryWrapper<SdUploadFile> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SdUploadFile::getBusiId, tbNewerTask.getTaskId());
        List<SdUploadFile> sdUploadFiles = sdUploadFileMapper.selectList(queryWrapper);
        sdUploadFiles.forEach(file -> commService.deleteSfsFile(file.getFileId()));
        return tbNewerTask.getTaskId();
    }

    /**
     * @title: deleteDto
     * @description: 删除操作
     * @params: [ dto ]
     * @return: Integer
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public Integer deleteDto(TbNewerTaskDTO dto) {
        if (!commService.checkLoginUserRole(BusiEnumDefine.USER_ROLE_ADMIN)) {
            TbNewerTask newerTask = tbNewerTaskMapper.selectById(dto.getTaskId());
            String creatorInfo = newerTask.getCreatorInfo();
            String userIdAndName = commService.getLoginUserNameAndId();
            if (!creatorInfo.equals(userIdAndName)) {
                throw new BusinessException(StatusCodeEnum.UN_AUTH); //创建人和登录人不一样，无权限
            }
        }
        if (StringUtils.isBlank(dto.getTaskId())) {
            throw new BusinessException(StatusCodeEnum.UNKNOW_ERROR.getCode(), "参数错误");
        }
        //删除文件
        QueryWrapper<SdUploadFile> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SdUploadFile::getBusiId, dto.getTaskId());
        List<SdUploadFile> sdUploadFiles = sdUploadFileMapper.selectList(queryWrapper);
        sdUploadFiles.forEach(file -> commService.deleteSfsFile(file.getFileId()));
        return tbNewerTaskMapper.deleteById(dto.getTaskId());
    }

    /**
     * 发布任务
     *
     * @param taskIdList
     * @return
     */
    @Override
    @Transactional
    public String postTask(List<TbNewerTaskDTO> taskIdList) {

        if (!commService.checkLoginUserRole(BusiEnumDefine.USER_ROLE_ADMIN)) {
            for (TbNewerTaskDTO tbNewerTaskDTO : taskIdList) {
                if ("0".equals(tbNewerTaskDTO.getCanEdit())) {
                    throw new BusinessException(StatusCodeEnum.UN_AUTH.getCode(), "没有权限发布任务：[" + tbNewerTaskDTO.getTaskName() + "]");
                }
            }
        }

        //人员数据，获取状态为2的员工记录
        QueryWrapper<TbWorker> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TbWorker::getWorkerStatus, BusiEnumDefine.WORKER_STATUS_CONDUCT);
        List<TbWorker> workerList = tbWorkerMapper.selectList(queryWrapper);

        //插入员工任务关联表 发送邮件
        Map<String, String> res = postTaskByWorkerId(workerList, taskIdList);

        return res.get("emailNum");
    }

    /**
     * 给员工发布任务
     *
     * @param workerList    员工集合
     * @param newerTaskDTOS 指定小任务,可不填
     * @return existNum flow已存在的数量
     * emailNum 成功发送邮件数量
     */
    @Override
    public Map<String, String> postTaskByWorkerId(List<TbWorker> workerList, List<TbNewerTaskDTO> newerTaskDTOS) {
        String userId = commService.getLoginUserId();
        Date now = new Date();
        int taskStatus = BusiEnumDefine.FLOW_STATUS_EXECUTE_TASK;

        List<String> taskIds;
        if (newerTaskDTOS != null && !newerTaskDTOS.isEmpty()) {
            newerTaskDTOS = newerTaskDTOS.stream()
                    .filter(o -> Objects.equals(o.getEnableFlag(), 2) &&
                            (o.getTaskExpireDate() == null || now.before(o.getTaskExpireDate())))
                    .collect(Collectors.toList());
            taskIds = newerTaskDTOS.stream().map(TbNewerTaskDTO::getTaskId).collect(Collectors.toList());
        } else {
            QueryWrapper<TbNewerTask> taskQW = new QueryWrapper<>();
            taskQW.lambda().eq(TbNewerTask::getEnableFlag, 2)
                    .and(o -> o.isNull(TbNewerTask::getTaskExpireDate).or().gt(TbNewerTask::getTaskExpireDate, now));
            List<TbNewerTask> tbNewerTasks = tbNewerTaskMapper.selectList(taskQW);
            taskIds = tbNewerTasks.stream().map(TbNewerTask::getTaskId).collect(Collectors.toList());
            newerTaskDTOS = JSONArray.parseArray(JSONArray.toJSONString(tbNewerTasks), TbNewerTaskDTO.class);
        }
        if (taskIds.isEmpty()) {
            Map<String, String> empty = new HashMap<>();
            empty.put("code", "SUCCESS");
            empty.put("msg", "发送成功");
            empty.put("existNum", "0");
            empty.put("emailNum", "0");
            return empty;
        }

        //判断是否重复发布
        QueryWrapper<TbFlowInst> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TbFlowInst::getFlowCode, N5).in(TbFlowInst::getFlowNote, taskIds);
        List<TbFlowInst> flowInsts = tbflowINstMapper.selectList(queryWrapper);
        List<String> flowCodeNote = flowInsts.stream()
                .map(o -> o.getFlowCode() + o.getFlowNote() + o.getWorkerId()).collect(Collectors.toList());

        //获取发布小任务邮件
        SdEmailTemplate taskEmail = sdEmailTemplateMapper.selectById(BusiEnumDefine.NEW_TASK_EMAIL);
        String title = taskEmail.getEmailTemplateTitle();
        String content = taskEmail.getEmailTemplateContent();

        //一个个创建实体类保存
        int num = 0;
        List<TbFlowInst> saveList = new ArrayList<>();
        List<SdNoticeRecord> noticeList = new ArrayList<>();
        for (TbNewerTaskDTO taskDto : newerTaskDTOS) {
            String taskId = taskDto.getTaskId();
            Integer targetType = taskDto.getTargetType();
            String targetValue = taskDto.getTargetConfigValue();
            List<String> targetList = StringUtils.isBlank(targetValue) ? Collections.emptyList()
                    : Arrays.asList(targetValue.split(","));
            for (TbWorker worker : workerList) {
                String sign = N5 + taskId + worker.getWorkerId();
                if (flowCodeNote.contains(sign)) {
                    //已经存在，计数后下一个
                    num++;
                    continue;
                }

                //如果不是全体员工 判断是否在目标部门中
                if (!targetType.equals(1)) {
                    SdDept dept = commService.getDept(worker.getDirectDeptId());
                    String deptCodeChain = dept.getDeptCodeChain();
                    String[] deptCode = deptCodeChain.split("/");
                    int flag = 0;
                    for (String deptId : deptCode) {
                        if (targetList.contains(deptId)) {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0) {
                        num++;
                        continue;
                    }
                }

                TbFlowInst tbFlowInst = new TbFlowInst();
                tbFlowInst.setFlowId(IdWorker.nextId() + "");
                tbFlowInst.setFlowCode(N5);
                tbFlowInst.setFlowName(BusiEnumDefine.flowNameLittleTask);
                tbFlowInst.setWorkerId(worker.getWorkerId());
                tbFlowInst.setWorkerName(worker.getWorkerName());
                tbFlowInst.setWorkerDeptId(worker.getDirectDeptId());
                tbFlowInst.setFlowStatus(taskStatus); //执行小任务
                tbFlowInst.setCurrentStage(BusiEnumDefine.currentStageLittleTaskDoing);
                tbFlowInst.setCreateTime(now);
                tbFlowInst.setArriveTime(now);
                tbFlowInst.setApprovalUserIds(worker.getWorkerId());
                tbFlowInst.setFlowNote(taskId);
                saveList.add(tbFlowInst);

                //邮件
                SdNoticeRecord sdNoticeRecord = new SdNoticeRecord();
                sdNoticeRecord.setNoticeId(IdWorker.nextId() + "");
                sdNoticeRecord.setFlowId(tbFlowInst.getFlowId());
                sdNoticeRecord.setApplyUserId(userId);
                sdNoticeRecord.setNoticeType(BusiEnumDefine.NOTICE_TYPE_EMAIL);
                sdNoticeRecord.setTargetId(worker.getWorkerId());
                sdNoticeRecord.setTargetName(worker.getWorkerName());
                SdAllWorker allWorker = commService.getAllWorkerDoFromLocalCache(worker.getWorkerId());
                if (allWorker != null) {
                    sdNoticeRecord.setTargetEmail(allWorker.getEmail());
                }
                sdNoticeRecord.setNoticeTitle(title);
                sdNoticeRecord.setNoticeContent(content);
                sdNoticeRecord.setCreateTime(now);
                noticeList.add(sdNoticeRecord);
            }
        }
        iTbFlowInstService.insertBatch(saveList);

        //发送邮件
        commService.sendMessage(noticeList);

        //生成待办
        saveList.forEach(todoTaskService::initOrUpdateTodoTask);

        int emailNum = noticeList.size();
        Map<String, String> result = new HashMap<>();
        result.put("code", "SUCCESS");
        result.put("msg", "发送成功");
        result.put("existNum", String.valueOf(num));
        result.put("emailNum", String.valueOf(emailNum));
        return result;
    }

    @Override
    public List<SdUploadFile> getTaskFileList(String taskId) {
        QueryWrapper<SdUploadFile> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SdUploadFile::getBusiId, taskId);
        List<SdUploadFile> uploadFiles = sdUploadFileMapper.selectList(queryWrapper);
        return uploadFiles;
    }


    /**
     * @title: initFuzzyExample
     * @description: 初始化 模糊查询 example
     * @params: [ dto ]
     * @return: tk.mybatis.mapper.entity.Example
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    private Example initFuzzyExample(TbNewerTaskDTO dto) {
        Example example = InitExampleOrderByUtils.initExampleOrderBy(TbNewerTask.class, dto.getOrderBy());
        Example.Criteria criteriaName = example.createCriteria();
        if (null != dto) {
            if (null != dto.getTaskId() && !"".equals(dto.getTaskId())) {
                criteriaName.andLike("TaskId", "%" + dto.getTaskId() + "%");
            }
            if (null != dto.getTaskName() && !"".equals(dto.getTaskName())) {
                criteriaName.andLike("TaskName", "%" + dto.getTaskName() + "%");
            }
            if (null != dto.getTaskNote() && !"".equals(dto.getTaskNote())) {
                criteriaName.andLike("TaskNote", "%" + dto.getTaskNote() + "%");
            }
            if (null != dto.getTargetType() && !"".equals(dto.getTargetType())) {
                criteriaName.andLike("TargetType", "%" + dto.getTargetType() + "%");
            }
            if (null != dto.getTargetConfigValue() && !"".equals(dto.getTargetConfigValue())) {
                criteriaName.andLike("TargetConfigValue", "%" + dto.getTargetConfigValue() + "%");
            }
            if (null != dto.getTaskEntry() && !"".equals(dto.getTaskEntry())) {
                criteriaName.andLike("TaskEntry", "%" + dto.getTaskEntry() + "%");
            }
            if (null != dto.getTaskValidDate() && !"".equals(dto.getTaskValidDate())) {
                criteriaName.andLike("TaskValidDate", "%" + dto.getTaskValidDate() + "%");
            }
            if (null != dto.getTaskExpireDate() && !"".equals(dto.getTaskExpireDate())) {
                criteriaName.andLike("TaskExpireDate", "%" + dto.getTaskExpireDate() + "%");
            }
            if (null != dto.getTaskFinishLimit() && !"".equals(dto.getTaskFinishLimit())) {
                criteriaName.andLike("TaskFinishLimit", "%" + dto.getTaskFinishLimit() + "%");
            }
            if (null != dto.getTaskTargetWorker() && !"".equals(dto.getTaskTargetWorker())) {
                criteriaName.andLike("TaskTargetWorker", "%" + dto.getTaskTargetWorker() + "%");
            }
            if (null != dto.getApproverType() && !"".equals(dto.getApproverType())) {
                criteriaName.andLike("ApproverType", "%" + dto.getApproverType() + "%");
            }
            if (null != dto.getCreateTime() && !"".equals(dto.getCreateTime())) {
                criteriaName.andLike("CreateTime", "%" + dto.getCreateTime() + "%");
            }
            if (null != dto.getCreatorInfo() && !"".equals(dto.getCreatorInfo())) {
                criteriaName.andLike("CreatorInfo", "%" + dto.getCreatorInfo() + "%");
            }
            if (null != dto.getUpdateTime() && !"".equals(dto.getUpdateTime())) {
                criteriaName.andLike("UpdateTime", "%" + dto.getUpdateTime() + "%");
            }
            if (null != dto.getUpdatorInfo() && !"".equals(dto.getUpdatorInfo())) {
                criteriaName.andLike("UpdatorInfo", "%" + dto.getUpdatorInfo() + "%");
            }
            if (null != dto.getEnableFlag() && !"".equals(dto.getEnableFlag())) {
                criteriaName.andLike("EnableFlag", "%" + dto.getEnableFlag() + "%");
            }
            if (null != dto.getEffectNormalFlag() && !"".equals(dto.getEffectNormalFlag())) {
                criteriaName.andLike("EffectNormalFlag", "%" + dto.getEffectNormalFlag() + "%");
            }
        }
        return example;
    }

    /**
     * @title: initExample
     * @description: 初始化 精确查询 example
     * @params: [ dto ]
     * @return: tk.mybatis.mapper.entity.Example
     * @createTime: 2022-01-24
     * @version: 1.0
     * @author: l22886
     */
    private Example initExample(TbNewerTaskDTO dto) {
        Example example = InitExampleOrderByUtils.initExampleOrderBy(TbNewerTask.class, dto.getOrderBy());
        Example.Criteria criteriaName = example.createCriteria();
        if (null != dto) {
            if (null != dto.getTaskId() && !"".equals(dto.getTaskId())) {
                criteriaName.andEqualTo("TaskId", dto.getTaskId());
            }
            if (null != dto.getTaskName() && !"".equals(dto.getTaskName())) {
                criteriaName.andEqualTo("TaskName", dto.getTaskName());
            }
            if (null != dto.getTaskNote() && !"".equals(dto.getTaskNote())) {
                criteriaName.andEqualTo("TaskNote", dto.getTaskNote());
            }
            if (null != dto.getTargetType() && !"".equals(dto.getTargetType())) {
                criteriaName.andEqualTo("TargetType", dto.getTargetType());
            }
            if (null != dto.getTargetConfigValue() && !"".equals(dto.getTargetConfigValue())) {
                criteriaName.andEqualTo("TargetConfigValue", dto.getTargetConfigValue());
            }
            if (null != dto.getTaskEntry() && !"".equals(dto.getTaskEntry())) {
                criteriaName.andEqualTo("TaskEntry", dto.getTaskEntry());
            }
            if (null != dto.getTaskValidDate() && !"".equals(dto.getTaskValidDate())) {
                criteriaName.andEqualTo("TaskValidDate", dto.getTaskValidDate());
            }
            if (null != dto.getTaskExpireDate() && !"".equals(dto.getTaskExpireDate())) {
                criteriaName.andEqualTo("TaskExpireDate", dto.getTaskExpireDate());
            }
            if (null != dto.getTaskFinishLimit() && !"".equals(dto.getTaskFinishLimit())) {
                criteriaName.andEqualTo("TaskFinishLimit", dto.getTaskFinishLimit());
            }
            if (null != dto.getTaskTargetWorker() && !"".equals(dto.getTaskTargetWorker())) {
                criteriaName.andEqualTo("TaskTargetWorker", dto.getTaskTargetWorker());
            }
            if (null != dto.getApproverType() && !"".equals(dto.getApproverType())) {
                criteriaName.andEqualTo("ApproverType", dto.getApproverType());
            }
            if (null != dto.getCreateTime() && !"".equals(dto.getCreateTime())) {
                criteriaName.andEqualTo("CreateTime", dto.getCreateTime());
            }
            if (null != dto.getCreatorInfo() && !"".equals(dto.getCreatorInfo())) {
                criteriaName.andEqualTo("CreatorInfo", dto.getCreatorInfo());
            }
            if (null != dto.getUpdateTime() && !"".equals(dto.getUpdateTime())) {
                criteriaName.andEqualTo("UpdateTime", dto.getUpdateTime());
            }
            if (null != dto.getUpdatorInfo() && !"".equals(dto.getUpdatorInfo())) {
                criteriaName.andEqualTo("UpdatorInfo", dto.getUpdatorInfo());
            }
            if (null != dto.getEnableFlag() && !"".equals(dto.getEnableFlag())) {
                criteriaName.andEqualTo("EnableFlag", dto.getEnableFlag());
            }
            if (null != dto.getEffectNormalFlag() && !"".equals(dto.getEffectNormalFlag())) {
                criteriaName.andEqualTo("EffectNormalFlag", dto.getEffectNormalFlag());
            }
        }
        return example;
    }


}
